require 'test/unit'
RUN = 'ruby lib/s3sync.rb'

class TestS3Sync < Test::Unit::TestCase
  # def setup
  # end
  
  # def teardown
  # end
  
  def test_version
    v = `#{RUN} -version`
    assert_equal v, `#{RUN} -v`
    assert_match(/\d+\.\d+\.\d+/, v) 
  end
  
  def test_help
    v = `#{RUN} --help`
    assert_equal v, `#{RUN} -h`
    assert_match(/\d+\.\d+\.\d+/, v) 
    
  end
  
  def test_should_stop_without_config
    assert_match(/not found/i,`#{RUN}`)
  end
  
  def test_should_stop_when_config_does_not_exist
    c = `#{RUN} -c does-not-exist.yml`
    assert_equal c, `#{RUN} --config does-not-exist.yml`
    assert_match(/config file/i, c)
  end
  
  def test_should_stop_with_absolute_path
    assert_match(/config file/i,`#{RUN} -c /NOT_ALLOWED.yml`)
  end

  def test_should_parse_invalid_config
    assert_match(/config example/i,`#{RUN} -c test-config/invalid.yml`)
  end
  
  def test_should_stop_without_keys
    assert_match(/required.*aws_.*_key/im ,`#{RUN} -c test-config/no-keys.yml`)
  end
  
  def test_should_stop_with_blank_keys
    assert_match(/required.*aws_.*_key/im ,`#{RUN} -c test-config/blank-keys.yml`)
  end
  
end
